﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HKEA.CMS.Core.IDAL.Tbl;
using HKEA.CMS.Core.Models;
using HKEA.CMS.Core.DALFactory;
using HKEA.CMS.Core.Utility;
using iMaker.Library;

namespace HKEA.CMS.Core.BLL.Tbl
{
    public class tblCust_WebLoginBLL
    {
        private  ItblCust_WebLogin IDAL;
        public tblCust_WebLoginBLL()
        {
            IDAL = DataAccess.CreateItblCust_WebLogin();
        }
        /// <summary>
        /// 创建对象
        /// </summary>
        /// <returns></returns>
        public static tblCust_WebLoginBLL GetInstance()
        {
            return new tblCust_WebLoginBLL();
        }

        /// <summary>
        /// 根据自增id获取 一条记录
        /// </summary>
        /// <param name="uid">自增ID</param>
        /// <returns>一条记录</returns>
        public tblCust_WebLogin GetENT(int uid)
        {
            try
            {
                return IDAL.GetENT(uid);
            }
            catch (Exception e)
            {
                throw e;
            }
        }

        /// <summary>
        /// 插入一条记录
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int InsertENT(tblCust_WebLogin ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret= IDAL.InsertENT(ent);
                }
                catch (Exception)
                {
                    
                    throw;
                }
            }
            return ret;
        }
        /// <summary>
        /// 物理删除
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int DeleteENT(tblCust_WebLogin ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.DeleteENT(ent);
                }
                catch (Exception)
                {

                    throw;
                }
            }
            return ret;
        }
        /// <summary>
        /// 修改记录
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int UpdateENT(tblCust_WebLogin ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.UpdateENT(ent);
                }
                catch (Exception)
                {

                    throw;
                }
            }
            return ret;
        }
        /// <summary>
        /// 登录验证,登录成功返回{LoginUID}_{CustomerUID},否则否则返回值为空
        /// </summary>
        /// <param name="strUserID"></param>
        /// <param name="strPWD"></param>
        /// <returns></returns>
        public string LoginMethod(string strUserID,string strPWD)
        {
            string ret = string.Empty;
            if (!string.IsNullOrEmpty(strUserID) && !string.IsNullOrEmpty(strPWD))
            {
                try
                {
                    ret = IDAL.LoginMethod(strUserID, strPWD); 
                }
                catch (Exception er) { }
            }
            return ret;
        }

        /// <summary>
        /// 根据条件得到符合条件的结果集，带分页参数
        /// </summary>
        /// <param name="ent"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<tblCust_WebLogin> GetListByENT(tblCust_WebLogin ent,PagerCollection param, string strPropertyName,string strOrderBy)
        {
            List<tblCust_WebLogin> list=new List<tblCust_WebLogin>();
            if (ent != null && param != null)
            {
                try
                {
                    list= IDAL.GetListByENT(ent,param,strPropertyName,strOrderBy);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return list;
        }
        /// <summary>
        /// 根据条件得到符合条件的结果集，不带分页参数
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public List<tblCust_WebLogin> GetListByENT(tblCust_WebLogin ent)
        {
            List<tblCust_WebLogin> list = new List<tblCust_WebLogin>();
            if (ent != null)
            {
                try
                {
                    list = IDAL.GetListByENT(ent);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return list;
        }
        /// <summary>
        /// 根据条件得到符合条件的记录条数
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int GetCountByENT(tblCust_WebLogin ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.GetCountByENT(ent);
                }
                catch (Exception)
                {
                    
                    throw;
                }
            }
            return ret;
        }
        /// <summary>
        /// 判断是否已存在符合条件的记录
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public bool IsExist(tblCust_WebLogin ent)
        {
            bool ret = false;
            if (ent != null)
            {
                if (GetCountByENT(ent) > 0)
                    ret = true;
            }
            return ret;
        }
    }
}
